
//1.基础数据类型
let str: string = "hello"
let num: number = 100
let bool: boolean = true

//2.数组
let arr: number[] = [1, 2, 3]
let arr2: Array<number> = [1, 2, 3]

//3.any,几乎任何类型的值都合法

//4.函数
function main(name: string): void {

}

function main2(name: string): boolean {
    return false
}

//5.对象类型
function print(obj: { x: number, y?: string }) {
    console.log(obj.x, obj.y);

}

print({
    x: 3,
    y: "haha1"
})
//y?: string ?表示可选参数
print({
    x: 3,
})

//6.联合类型(union类型)
//两个或者多个不同类型组成的类型
function printId(id: number | string) {
    if (typeof id === 'string') {
        console.log(id.toUpperCase());
    } else {
        console.log(id);
    }

}

printId(100)
printId("haha")

function welcomePeople(x: string | string[]) {
    if (Array.isArray(x)) {
        console.log("hello:" + x.join(' and '));
    } else {
        console.log("hello:" + x);
    }
}

welcomePeople("a")
welcomePeople(['a', 'b'])

//7.类型别名
type Point = {
    x: number,
    y: number
}
type ID = number | string

function print2(pt: Point) {

}

print2({ x: 1, y: 2 })


//8.接口
interface Point2{
    x:number,
    y:number
}

function print3(pt: Point2) {

}

print3({ x: 1, y: 2 })







